package com.puff.service.impl;

import com.puff.context.BaseContext;
import com.puff.dto.PaymentDTO;
import com.puff.entity.Payment;
import com.puff.mapper.PaymentMapper;
import com.puff.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@Slf4j
public class PaymentServiceImpl implements PaymentService {

    @Autowired
    private PaymentMapper paymentMapper;

    /**
     * 支付
     * @param paymentDTO
     */
    public void pay(PaymentDTO paymentDTO) {
        Payment payment = new Payment();
        //对象拷贝
        BeanUtils.copyProperties(paymentDTO,payment);

        Long userId = BaseContext.getCurrentId();
        payment.setPaymentTime(LocalDateTime.now());
        payment.setUserId(userId);

        paymentMapper.pay(payment);
    }
}
